package com.kcsoft.mapper;

import com.kcsoft.pojo.KeyAll;
import com.kcsoft.pojo.KeyTotal;
import com.kcsoft.pojo.KeyWord;
import com.kcsoft.pojo.Result;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface KeyWordMapper {

    @Select("select * from dxai.keyword where create_time between #{startOfDay} and #{endOfDay}")
    List<KeyWord> getKeyWords(LocalDateTime startOfDay, LocalDateTime endOfDay);

    @Insert("insert into dxai.keytotal(keyword,total,create_time) values(#{keyWord},#{total},#{createTime})")
    void saveKeyTotal(KeyTotal res);

    @Select("select * from dxai.keytotal where create_time=#{date}")
    List<KeyTotal> getTotal(LocalDate date);

    @Insert("insert into dxai.keyword(key_word,create_time) values(#{key},now())")
    void saveKey(String key);

    @Select("select keyword, sum(total) as all_total from dxai.keytotal group by keyword")
    List<KeyAll> getAll();
}
